package com.xiaobai.data.manager.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaobai.model.entity.system.Menu;
import com.xiaobai.data.manager.system.MenuManager;
import com.xiaobai.data.mapper.system.MenuMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@AllArgsConstructor
public class MenuManagerImpl extends ServiceImpl<MenuMapper, Menu> implements MenuManager  {

    private final MenuMapper menuMapper;

    @Override
    public List<Menu> getMenuListByUserId(Long id) {
        return menuMapper.getMenuListByUserId(id);
    }

    @Override
    public List<Menu> getMenuTree() {
        return this.list(new LambdaQueryWrapper<Menu>().eq(Menu::getStatus, 1));
    }

    @Override
    public Menu getMenuByAuthority(String name) {
        return this.getOne(new LambdaQueryWrapper<Menu>().eq(Menu::getMenuName, name), false);
    }

    @Override
    public Menu getMenuByIdAuthority(Long id, String name) {
        return this.getOne(new LambdaQueryWrapper<Menu>().eq(Menu::getMenuName, name).ne(Menu::getId, id), false);
    }

    @Override
    public List<Menu> getMenuByIds(List<Long> menuIds) {
        return this.list(new LambdaQueryWrapper<Menu>().in(Menu::getId, menuIds));
    }
}
